home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / docs / mags / DC4_Guide.lha / DC4_Guide / Mag4_Guide / DC4_ADVENTURE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-22  |  4.1 KB  |  194 lines

  1. /*
  2.    Adventure
  3.     (c)1997 Mark Harman
  4.  
  5.     C++, Compiled using GNU-C
  6.  
  7. */
  8.  
  9. // Preprocessor crap
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>   // for rand()
  13. #include <string.h>   // for strcpy()
  14.  
  15. // Constants
  16.  
  17. const int NOSTATS=5;
  18.  
  19. // Structure Declarations
  20.  
  21. struct character
  22. {
  23.    char Name[64];
  24.    char Background[1024];
  25.    int  Sex,Race,Profession,Age;
  26.    int Stat[NOSTATS];
  27. };
  28.  
  29. struct chars
  30. {
  31.    char Name[64];
  32. };
  33.  
  34. // Variable Declarations
  35.  
  36. chars Races[4] = {{"Human"}, {"Elf"}, {"Dwarf"}, {"Halfling"}};
  37. chars Professions[4]={{"Warrior"}, {"Ranger"}, {"Thief"}, {"Academic"}};
  38. chars StatNames[NOSTATS] = {{"HS"}, {"RS"}, {"S "}, {"T "}, {"HR"}};
  39.  
  40. // Funtion Declarations
  41.  
  42. void introtext();
  43. void randomize(char * Word);
  44. character chargen();
  45. void getbackground(char * To,character PC);
  46. int getlistresponse(chars List[],int N);
  47. character displaypcinfo(character PC,int What);
  48. int roll(int X,int Y,int Z);
  49.  
  50. // main
  51.  
  52. void main()
  53. {
  54.    introtext();
  55.  
  56.    character Player;
  57.    Player=chargen();
  58.    displaypcinfo(Player,7);
  59. }
  60.  
  61. void introtext()
  62. {
  63.    printf("     Adventurer!\n");
  64.    printf("        v0.01\n");
  65.    printf("        alpha\n\n");
  66.  
  67.    printf("       (c)1997\n");
  68.    printf("     Mark Harman\n\n");
  69. }
  70.  
  71. void randomize(char * Word)
  72. {
  73.    // a feeble attempt to 'randomize' the rand() function
  74.    // by calling rand() a number of times dependant on the PC's name
  75.    for(int k=0;k<*Word;k++)
  76.       rand();
  77. }
  78.  
  79. character chargen()
  80. {
  81.    // generates a PC according to struct character
  82.  
  83.    struct character PC;
  84.    printf("Character Generation...\n\n");
  85.  
  86.    printf("Please a name for your character (One Word Only!) :\n");
  87.    scanf("%s",&PC.Name);
  88.    randomize(PC.Name);
  89.  
  90.    printf("Please select a Race:\n");
  91.    PC.Race=getlistresponse(Races,4);
  92.  
  93.    printf("Please select a Profession:\n");
  94.    PC.Profession=getlistresponse(Professions,4);
  95.  
  96.    // main stats
  97.    switch(PC.Race)
  98.    {
  99.       case 0 :
  100.          // Human
  101.          PC.Age=roll(2,8,18);
  102.          PC.Stat[0]=roll(2,10,20);
  103.          PC.Stat[1]=roll(2,10,20);
  104.          PC.Stat[2]=roll(2,10,20);
  105.          PC.Stat[3]=roll(2,10,20);
  106.          PC.Stat[4]=roll(6,10,180);
  107.          break;
  108.       case 1 :
  109.          // Elf
  110.          PC.Age=roll(4,10,180);
  111.          PC.Stat[0]=roll(2,10,20);
  112.          PC.Stat[1]=roll(2,10,30);
  113.          PC.Stat[2]=roll(2,10,10);
  114.          PC.Stat[3]=roll(2,10,15);
  115.          PC.Stat[4]=roll(6,10,140);
  116.          break;
  117.       case 2 :
  118.          // Dwarf
  119.          PC.Age=roll(2,10,90);
  120.          PC.Stat[0]=roll(2,10,30);
  121.          PC.Stat[1]=roll(2,10,10);
  122.          PC.Stat[2]=roll(2,10,25);
  123.          PC.Stat[3]=roll(2,10,30);
  124.          PC.Stat[4]=roll(6,10,220);
  125.          break;
  126.       case 3 :
  127.          // Halfling
  128.          PC.Age=roll(2,8,60);
  129.          PC.Stat[0]=roll(2,10,20);
  130.          PC.Stat[1]=roll(2,10,20);
  131.          PC.Stat[2]=roll(2,10,15);
  132.          PC.Stat[3]=roll(2,10,15);
  133.          PC.Stat[4]=roll(6,10,160);
  134.          break;
  135.    }
  136.  
  137.    getbackground(PC.Background,PC);
  138.  
  139.    return PC;
  140. }
  141.  
  142. void getbackground(char * To,character PC)
  143. {
  144.    char Background[]="You had a nice childhood...\n  After many years, you decide to set out and explore the dangerous lands.\n";
  145.    strcpy(To,Background);
  146. }
  147.  
  148. int getlistresponse(chars List[],int N)
  149. {
  150.    // gets a response from a list displayed
  151.    int k,Response;
  152.    for(k=0;k<N;k++)
  153.       printf(" %d - %s,\n",k,List[k].Name);
  154.  
  155.    printf(">");
  156.    scanf("%d",&Response);
  157.    return Response; 
  158. }
  159.  
  160. character displaypcinfo(character PC,int What)
  161. {
  162.    // simple status screen
  163.    // What(bits): 1=main, 2=background, 3=equipment
  164.    if((What && 1)==1)
  165.    {
  166.       printf("Name       : %s\n",PC.Name);
  167.       printf("Race       : %s\n",Races[PC.Race].Name);
  168.       printf("Profession : %s\n",Professions[PC.Profession].Name);
  169.       printf("Age        : %d\n",PC.Age);
  170.       for(int k=0;k<NOSTATS;k++)
  171.          printf("%s         : %d\n",StatNames[k].Name,PC.Stat[k]);
  172.       printf("\n");
  173.    }
  174.    if((What && 2)==1)
  175.    {
  176.       printf("Background:\n");
  177.       printf("%s",PC.Background);
  178.       printf("\n");
  179.    }
  180. }
  181.  
  182. int roll(int X,int Y,int Z)
  183. {
  184.    // Roll X DY+Z
  185.    int val=0,tval;
  186.    for(int k=0;k<X;k++)
  187.    {
  188.       tval=rand() % Y;
  189.       val+=tval+1;
  190.    }
  191.    val+=Z;
  192.    return(val);
  193. }
  194.